/**
 * Created by Administrator on 2018/1/8.
 */
var obj = getSearchObj()
$(".elder-name").html(obj.elderName)
$(".elder-card-id").html(obj.elderCard)

var testLevelResultOne = null;
var testLevelResultList = [];
var resultModel1 = {};
var resultModel2 = {};
var resultModel3 = {};
var resultModel4 = [];
var levelResultModel = {};

var resultModels = {
    "testLevelResultOne": testLevelResultOne,
    "resultModel1": resultModel1,
    "resultModel2": resultModel2,
    "resultModel3": resultModel3,
    "resultModel4": resultModel4,
    "testLevelResultList":testLevelResultList,
    "levelResultModel":levelResultModel
};

var loginedUser = getLoginedUser();

var view = {
    data: resultModels,
};

var vue_vm = new Vue({
    el: '#vue_vm',
    data: view,
    methods:{
        checkResult(item){
            var elderData = "elderId="+item.elderId+"&elderName="+item.elderForm.name+"&elderCard="+item.elderForm.cardId+"&testTimesNumber="+item.testTimesNumber;
            location.href = "2-2-1cheping-result.html?"+elderData;
        }
    }
})

function  getData() {
    findTestLevelResultList();
    if(Number.parseInt(obj.testTimesNumber)!=0){
        getResult();
    }
}

function getResult() {
    findTestLevelResultOne();
    getResultModel1();
    getResultModel2();
    getResultModel3();
    getResultModel4();
    getLevelResultModel();
}

getData();

function findTestLevelResultOne() {
    find_basic_by_json(path + '/elderTestLevelRecord/findOne', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
    }, function (res) {
        view.data.testLevelResultOne = res.data[0];
        console.log(view.data.testLevelResultOne);
    });
}

function getResultModel1() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 1,
    }, function (res) {
        view.data.resultModel1 = res.data[0];

    });
}

function getResultModel2() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 2,
    }, function (res) {
        view.data.resultModel2 = res.data[0];
    });
}

function getResultModel3() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 3,
    }, function (res) {
        view.data.resultModel3 = res.data[0];
    });
}

function getLevelResultModel() {
    find_basic_by_json(path + '/testResultLevel/findAll', {}, function (res) {
        view.data.levelResultModel = res.data;
        console.log(view.data.levelResultModel);
    });
}

function getResultModel4() {
    find_basic_by_json(path + '/elderTestDiseaseRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 4,
    }, function (res) {
        view.data.resultModel4 = res.data;
        console.log("resultModel4=" + JSON.stringify(view.data.resultModel4));
    });
}



function  findTestLevelResultList() {
    find_basic_by_json(path + '/elderTestLevelRecord/findList', {
        "elderId": obj.elderId,
    }, function (res) {
        view.data.testLevelResultList = res.data;
        if(Number.parseInt(obj.testTimesNumber)==0&&view.data.testLevelResultList.length>0){
            obj.testTimesNumber = view.data.testLevelResultList[0].testTimesNumber;
            getResult();
        }
    });
}